const { resolve } = require('path');
const webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
  entry: {
    'index/index': './pages/index/index.js',// 导出至子目录
    'entry/entry': './pages/entry/entry.js'
  },
  output: {
    filename: '[name].bundle.js',
    // the output bundle

    path: resolve(__dirname, 'dist'),

    publicPath: '/'
    // necessary for HMR to know where to load the hot update chunks
  },

  module: {
    rules: [
      {
        test: /\.js$/,
        use: [
          'babel-loader',
        ],
        exclude: /node_modules/
      },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({fallback: "style-loader", use: "css-loader"}),
      },
      {
        test: /\.pug$/,
        use: [
          'pug-loader?pretty=    ',
        ]
      }
    ],
  },
  resolve: {
    alias: {
      'jquery-mousewheel': resolve(__dirname, 'src/pages/index/jquery-mousewheel.js'),
      'jquery-datetimepicker': resolve(__dirname, 'src/pages/index/jquery.datetimepicker.full.js'),
    }
  },
  externals: {
    jquery: 'window.jQuery'
  },

  context: resolve(__dirname, 'src'),

  devtool: 'inline-source-map',

  devServer: {
    hot: !true,
    // enable HMR on the server

    contentBase: resolve(__dirname, 'dist'),
    // match the output path

    publicPath: '/',
    // match the output `publicPath`
    
    port: 8090,

  },
  plugins: [
    new ExtractTextPlugin({
      filename: "[name].css",// css导出
      allChunks: !true
    }),
    new HtmlWebpackPlugin({
      filename: 'index/index.html',
      template: 'pages/index/index.pug',// html需各自设置
      chunks: ['index/index']
    }),
    new HtmlWebpackPlugin({
      filename: 'entry/index.html',
      template: 'pages/entry/entry.pug',
      chunks: ['entry/entry']
    }),/*
    new webpack.optimize.UglifyJsPlugin({
        beautify: false,
        mangle: {
            screw_ie8: true,
            keep_fnames: true,
            // except: ['$super', '$', 'exports', 'require']
        },
        compress: {
            screw_ie8: true,
            warnings: false
        },
        comments: false
    })*/
    // new webpack.HotModuleReplacementPlugin(),
    // enable HMR globally

    // new webpack.NamedModulesPlugin(),
    // prints more readable module names in the browser console on HMR updates
  ],
};